package com.byzk.p2p.front.listener;

import javax.servlet.http.HttpSessionAttributeListener;
import javax.servlet.http.HttpSessionBindingEvent;

import com.byzk.p2p.admin.user.dto.User;
import com.byzk.p2p.front.session.UserSession;

public class SessionAttributeListener implements HttpSessionAttributeListener{

	/**
	 * 添加session
	 */
	@Override
	public void attributeAdded(HttpSessionBindingEvent se) {
		if ("_user".equals(se.getName())) {    
			UserSession.set((User) se.getValue());  
        }
		
	}

	/**
	 * 销毁Session
	 */
	@Override
	public void attributeRemoved(HttpSessionBindingEvent se) {
		if("_user".equals(se.getName())){  
			UserSession.remove();    
		}       
		
	}

	/**
	 * 替代Session
	 */
	@Override
	public void attributeReplaced(HttpSessionBindingEvent se) {
		if ("_user".equals(se.getName())) {    
			UserSession.set((User)se.getValue());    
        } 
		
	}

}
